<template>
  <div class="container">
    <div class="alphabet">
      <h3 class="title">按拼音首字母选择:</h3>
      <p class="info">
        <span v-for="(item, index) of alphabet" :key="index">
          <a :href="item.href">
            {{item.alphabet}}
          </a>
        </span>
      </p>
    </div>
    <div class="list-info">
      <div :id="index" v-for="(item, index) of allCityList" :key="index" class="list-info-item">
        <span class="list-info-item-alphabet">{{item.initial}}</span>
        <ul>
          <li @click="clickCity(index, indexs)" v-for="(items, indexs) of item.city" :key="indexs">{{items}}</li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'CityDetail',
  props: {
    alphabet: {
      type: Array,
      default() {
        return []
      }
    },
    allCityList: {
      type: Array,
      default() {
        return []
      }
    }
  },
  methods: {
    clickCity(index, indexs) {
      let city = this.allCityList[index].city[indexs]
      this.$store.dispatch('onlyChangeCity', city)
      this.$emit('saveCityRecord', city)
      this.$router.push('/')
    }
  }
}
</script>

<style lang="scss" scoped>
.container {
  .alphabet {
    background: #fff;
    padding: 30px 0;
    display: flex;
    align-items: center;
    .title {
      font-size: 16px;
      color: #333;
      font-weight: 500;
      vertical-align: top;
      display: inline-block;
    }
    .info {
      font-size: 14px;
      vertical-align: top;
      display: inline-block;
      margin-top: 2px;
      span {
        font-size: 15px;
        margin: 0 17px;
        display: inline-block;
        margin: 0 10px;
        width: 25px;
        height: 25px;
        padding-top: 2px;
        cursor: pointer;
        box-sizing: border-box;
        text-align: center;
        border-radius: 50%;
        a {
          color: #666;
        }
        &:hover {
          font-weight: 500;
          color: #222222;
          background: #F8F8F8;
        }
      }
    }
  }
  .list-info {
    background-color: #fff;
    &-item {
      padding: 13px 30px 13px 10px;
      border-radius: 10px;
      transition: background-color 500ms;
      &:hover {
        background-color: #F8F8F8;
        border-radius: 10px;
      }
      &-alphabet {
        box-sizing: border-box;
        vertical-align: top;
        padding-top: 10px;
        display: inline-block;
        text-align: center;
        width: 40px;
        height: 40px;
        border-radius: 50%;
        color: #222222;
        background: #FFD000;
      }
      ul {
        display: inline-block;
        max-width: 1065px;
        li {
          margin: 10px 20px;
          color: #666;
          display: inline-block;
          cursor: pointer;
          font-size: 14px;
          &:hover {
            color: #222222;
            font-weight: 500;
          }
        }
      }
    }
  }
}
</style>